﻿using UnityEngine;
using System;
using System.Collections;

public abstract class IManager<T> : MonoBehaviour{

	private bool initialized = false;

	protected static T instance;  

	public static T Instance  
	{  
		get  
		{  
			if (instance == null) {

				Type type = typeof(T);
				GameObject go = new GameObject (type.Name);
				DontDestroyOnLoad(go);
				go.AddComponent(type);

				instance = go.GetComponent<T> ();
			}
			return instance;  
		}  
	}

	protected void MarkInitialized()
	{
		this.initialized = true;
	}

	public virtual bool Init(){
		if (initialized) {
			Debug.Log("Has already initialized!");
			return false;
		}
		return true;
	}

	public virtual void Reset(){
	}

	public virtual void Destroy(){
	}

	void Update () {
		this.UpdateManger ();
	}

	protected abstract void UpdateManger();
}
